package pers.qianyu.month_202101.date_20210110;

import java.util.*;
import java.util.stream.*;

/**
 * 762. 二进制表示中质数个计算置位
 * https://leetcode-cn.com/problems/prime-number-of-set-bits-in-binary-representation/
 *
 * @author mizzle rain
 * @date 2021-01-10 11:27
 */
public class CountPrimeSetBits {
    public int countPrimeSetBits(int L, int R) {
        Set<Integer> primes = Stream.of(2, 3, 5, 7, 11, 13, 17, 19).collect(Collectors.toSet());
        int res = 0;
        for (int i = L; i <= R; i++) {
            int count = 0;
            for (int j = 0; j < 32; j++) {
                count += (i >> j) & 1;
            }
            if (primes.contains(count)) {
                res++;
            }
        }
        return res;
    }
}
